package tr.richfacesext.components.itemsorter;

import javax.faces.component.UIData;
import javax.faces.context.FacesContext;
import javax.faces.el.MethodBinding;
import javax.faces.el.ValueBinding;

/**
 * 
 * @author mert
 *
 */
public class ItemSorter extends UIData {

	private Integer _width = new Integer(600); // by default
	
	public ItemSorter() {
		setRendererType(ItemSorterConstants.DEFAULT_RENDERER);
	}

	public String getFamily() {
		return ItemSorterConstants.COMPONENT_FAMILY;
	}

	public Object saveState(FacesContext context) {
		Object values[] = new Object[2];
		values[0] = super.saveState(context);
		values[1] = _width; 
		
		return ((Object) values);
	}
	
	public void restoreState(FacesContext context, Object state) {
		Object values[] = (Object[]) state;
		super.restoreState(context, values[0]);
		_width = (Integer) values[1];
		
		super.restoreState(context, values[0]);
	}
	
	public Integer getWidth() {
		if(_width != null )
			return _width;

		ValueBinding vb = getValueBinding("width");
		return vb != null ? (java.lang.Integer) vb.getValue(getFacesContext()) : null;
	}
	
	public void setWidth(Integer value) {
		_width = value;
	}
}